
package com.seekting.study;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class TestImageUrlConncetion {

    public static void main(String[] args) {
        String s =
                "http://d39vfkuubets9i.cloudfront.net/wallpaper/s_1920_2160_wallpaper1420451314.jpg";
        long time = System.currentTimeMillis();
        try {
            URL url = new URL(s);
            URLConnection con = url.openConnection();
            InputStream inputStream = con.getInputStream();
            // ByteArrayOutputStream byteArrayOutputStream = new
            // ByteArrayOutputStream();
             byte[] bytes = new byte[2160];
             int length = 0;
            // while ((length = inputStream.read(bytes, 0, bytes.length)) > 0) {
            // // byteArrayOutputStream.write(bytes, 0, length);
            // }
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
             while ((length = bufferedInputStream.read(bytes, 0, bytes.length)) > 0) {
             // byteArrayOutputStream.write(bytes, 0, length);
             }
            long wtime = System.currentTimeMillis() - time;
            // long wtime = System.currentTimeMillis() - time;
            System.out.println("read over!" + wtime);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
